package com.todaynews.utils;

import android.content.Context;
import com.alipay.euler.andfix.patch.PatchManager;
import java.io.IOException;

/**
 * 管理阿里AndFix所有api
 */
public class AndFixPatchManager {

    private static AndFixPatchManager instance = null;
    private static PatchManager patchManager = null;
    public static AndFixPatchManager getInstance(){
        if (instance == null){
            synchronized (AndFixPatchManager.class){
                if (instance == null) {
                    instance = new AndFixPatchManager();
                }
            }
        }
        return instance;
    }

    /**
     * 初始化AndFix方法
     * @param context
     */
    public void initPatch(Context context){
        patchManager = new PatchManager(context);
        patchManager.init(ApkUtils.getInstance().getVersionName());
        patchManager.loadPatch();
    }

    /**
     * 加载patch文件
     * @param path
     */
    public void addPatch(String path){
        if(patchManager != null){
            try {
                patchManager.addPatch(path);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
